package com.roc.steelend.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roc.steelend.controller.vo.returnformat.ReturnMsgForTable;
import com.roc.steelend.mapper.GroupClientMapper;
import com.roc.steelend.pojo.GroupClient;
import com.roc.steelend.service.GroupClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class GroupClientServiceImpl implements GroupClientService {

    @Autowired
    private GroupClientMapper groupClientMapper;

    @Override
    public List<GroupClient> findAllGroupClient() {
        return groupClientMapper.selectList(null);
    }

    @Override
    public ReturnMsgForTable findGroupClient(String selectMsg, Integer now, Integer size) {
        Page<GroupClient> page = new Page<>(now,size);
        QueryWrapper<GroupClient> wrapper = new QueryWrapper<>();

        if (selectMsg!=null && !selectMsg.equals("")){
            wrapper.like("group_client_name",selectMsg);

        }
         groupClientMapper.selectPage(page,wrapper);
        ReturnMsgForTable returnMsgForTable = new ReturnMsgForTable();
        returnMsgForTable.setObjectList(page.getRecords());
        returnMsgForTable.setCurrenPage(now);
        long total = page.getTotal();
        Integer integer = Integer.valueOf(String.valueOf(total));
        returnMsgForTable.setTotal(integer);
        return  returnMsgForTable;
    }
}
